﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SPSimpleDeveloper.Common.Helpers; 

namespace SPSimpleDeveloper.DAL.Tests
{
    /// <summary>
    /// Verifies read of embedded file as resource
    /// </summary>
    [TestClass]
    public class EmbeddedFilesTest
    {
        /// <summary>
        /// Test for sample text file
        /// </summary>
        [TestMethod]
        public void ReadSampleFile_ShouldReturnContent()
        {
            EmbeddedFilesHelper helper = new EmbeddedFilesHelper();
            string content = helper.ReadFileContent("SPSimpleDeveloper.DAL.Resources.", "sample.txt");
           
            Assert.IsNotNull(content);
            Assert.IsTrue(!string.IsNullOrEmpty(content));
        }

        /// <summary>
        /// For any exception, e.g. wrong path content is returned as null
        /// </summary>
        [TestMethod]
        public void ReadSampleFile_IncorrectFileName_ShouldReturnNull()
        {
            EmbeddedFilesHelper helper = new EmbeddedFilesHelper();
            string content = helper.ReadFileContent("SPSimpleDeveloper.DAL.Resources.", "notexistingfile.txt");

            Assert.IsNull(content); 
        }

        /// <summary>
        /// Tries to read file with empty file name
        /// </summary>
        [TestMethod]
        public void ReadFile_NoName_ShouldReturnNull()
        {
            EmbeddedFilesHelper helper = new EmbeddedFilesHelper();
            string content = helper.ReadFileContent("SPSimpleDeveloper.DAL.Resources.", string.Empty);

            Assert.IsNull(content); 
        }

        /// <summary>
        /// Null passed as filename
        /// </summary>
        [TestMethod]
        public void ReadFile_Null_ShouldReturnNull()
        {
            EmbeddedFilesHelper helper = new EmbeddedFilesHelper();
            string content = helper.ReadFileContent("SPSimpleDeveloper.DAL.Resources.", null);

            Assert.IsNull(content);
        }

        /// <summary>
        /// Reads embedded content type file
        /// </summary>
        [TestMethod]
        public void ReadContentTypeFile_ShouldReturnContent()
        {
            string path = Consts.Paths.ContentTypePath;
            string filename = Consts.Paths.ContentTypeFileName;

            EmbeddedFilesHelper helper = new EmbeddedFilesHelper();
            string content = helper.ReadFileContent(path, filename);

            Assert.IsTrue(!content.IsNullOrEmpty());
        }

    }
}
